#include "changeinformation.h"
#include "ui_changeinformation.h"
#include <QDebug>
#include <QJsonObject>
#include <QJsonDocument>
#include <QJsonArray>
#include <QMouseEvent>


changeinformation::changeinformation(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::changeinformation)
{
    ui->setupUi(this);
       this->setWindowFlags(Qt::FramelessWindowHint);
}


changeinformation::changeinformation(QString&selfname,QString&selfaccount,QString&selfpic,QString&selfsig):
  // QDialog(parent),
   ui(new Ui::changeinformation)
{
    ui->setupUi(this);
    this->setWindowFlags(Qt::FramelessWindowHint);
    QWidget *parent = nullptr;
    ui->name_value->setText(selfname);
    ui->sig_value->setText(selfsig);
    QString qs="border-image: url("+selfpic+");";
    ui->label_5->setStyleSheet(qs);
    picpath=selfpic;
    ui->name_value->setStyleSheet("background:transparent;border-width:0;border-top:1px  solid;border-bottom:1px  solid;border-left:1px  solid;border-right: 1px  solid;border-style:outset");
    ui->sig_value->setStyleSheet("background:transparent;border-width:0;border-top:1px  solid;border-bottom:1px  solid;border-left:1px  solid;border-right: 1px  solid;border-style:outset");




    tcpSocket=new QTcpSocket(this);
    tcpSocket->connectToHost("localhost",8022);
    connect(tcpSocket, &QTcpSocket::connected, this, &changeinformation::slotConnected);

    //   connect(tcpSocket, &QTcpSocket::readyRead, this, &changeinformation::onReadyRead);
    connect(tcpSocket, &QTcpSocket::disconnected, this, &changeinformation::slotDisconnected);


    connect(ui->pushButton,&QPushButton::clicked,this,[=]{
        QString n=ui->name_value->text();
        QString signature=ui->sig_value->toPlainText();
        QJsonObject dataObject;
        dataObject["sendtype"]="changeinformation";
        dataObject["selfname"]=n;
        dataObject["selfaccount"]=selfaccount;
        dataObject["selfpic"]=picpath;
        dataObject["selfsig"]=signature;
        QJsonDocument dataDocument(dataObject);
        QByteArray jsonData=dataDocument.toJson();
        tcpSocket->write(jsonData);
        this->close();
    });

}
changeinformation::~changeinformation()
{
    delete ui;
}

void changeinformation::on_toolButton_clicked()
{
    picpath=":/new/pre/resource/head/111.jpg";
    QString s="border-image: url("+picpath+");";
        ui->label_5->setStyleSheet(s);
}

void changeinformation::on_toolButton_2_clicked()
{
    picpath=":/new/pre/resource/head/222.jpg";
    QString s="border-image: url("+picpath+");";
        ui->label_5->setStyleSheet(s);
}


void changeinformation::on_toolButton_3_clicked()
{
   picpath=":/new/pre/resource/head/333.jpg";
    QString s="border-image: url("+picpath+");";
        ui->label_5->setStyleSheet(s);
}


void changeinformation::on_toolButton_4_clicked()
{
    picpath=":/new/pre/resource/head/444.jpg";
    QString s="border-image: url("+picpath+");";
        ui->label_5->setStyleSheet(s);
}


void changeinformation::on_toolButton_5_clicked()
{
    picpath=":/new/pre/resource/head/555.jpg";
    QString s="border-image: url("+picpath+");";
        ui->label_5->setStyleSheet(s);
}



void changeinformation::on_toolButton_6_clicked()
{
    picpath=":/new/pre/resource/head/666.jpg";
    QString s="border-image: url("+picpath+");";
        ui->label_5->setStyleSheet(s);
}



void changeinformation::on_toolButton_7_clicked()
{
    picpath=":/new/pre/resource/head/777.jpg";
    QString s="border-image: url("+picpath+");";
        ui->label_5->setStyleSheet(s);
}



void changeinformation::on_toolButton_8_clicked()
{
   picpath=":/new/pre/resource/head/888.jpg";
    QString s="border-image: url("+picpath+");";
        ui->label_5->setStyleSheet(s);
}

void changeinformation::slotConnected(){
    qDebug()<<"调用 chatWindow 的slotConnected函数"<<endl;
}

void changeinformation::slotDisconnected(){
    qDebug()<<"调用 chatWindow 的slotDisconnected函数"<<endl;
}


void changeinformation::on_toolButton_10_clicked()
{
    this->close();
}

void changeinformation::on_toolButton_9_clicked()
{
    this->showMinimized();
}

void changeinformation::mousePressEvent(QMouseEvent *event)
{
    this->windowPos = this->pos();       // 获得部件当前位置
    this->mousePos = event->globalPos(); // 获得鼠标位置
    this->dPos = mousePos - windowPos;   // 移动后部件所在的位置
}

void changeinformation::mouseMoveEvent(QMouseEvent *event)
{
    this->move(event->globalPos() - this->dPos);
}
